home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.1 / a2p.1 next >
Text File  |  1995-07-25  |  9KB  |  199 lines

  1.  
  2.  
  3.  
  4.      AAAA2222PPPP((((1111))))                UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((LLLLOOOOCCCCAAAALLLL))))                AAAA2222PPPP((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.           a2p - Awk to Perl translator
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.           aaaa2222pppp [[[[ooooppppttttiiiioooonnnnssss]]]] ffffiiiilllleeeennnnaaaammmmeeee
  13.  
  14.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  15.           _A_2_p takes an awk script specified on the command line (or
  16.           from standard input) and produces a comparable _p_e_r_l script
  17.           on the standard output.
  18.  
  19.           OOOOppppttttiiiioooonnnnssss
  20.  
  21.           Options include:
  22.  
  23.           ----DDDD<<<<nnnnuuuummmmbbbbeeeerrrr>>>>
  24.                sets debugging flags.
  25.  
  26.           ----FFFF<<<<cccchhhhaaaarrrraaaacccctttteeeerrrr>>>>
  27.                tells a2p that this awk script is always invoked with
  28.                this -F switch.
  29.  
  30.           ----nnnn<<<<ffffiiiieeeellllddddlllliiiisssstttt>>>>
  31.                specifies the names of the input fields if input does
  32.                not have to be split into an array.  If you were
  33.                translating an awk script that processes the password
  34.                file, you might say:
  35.  
  36.                     a2p -7 -nlogin.password.uid.gid.gcos.shell.home
  37.  
  38.                Any delimiter can be used to separate the field names.
  39.  
  40.           ----<<<<nnnnuuuummmmbbbbeeeerrrr>>>>
  41.                causes a2p to assume that input will always have that
  42.                many fields.
  43.  
  44.           CCCCoooonnnnssssiiiiddddeeeerrrraaaattttiiiioooonnnnssss
  45.  
  46.           A2p cannot do as good a job translating as a human would,
  47.           but it usually does pretty well.  There are some areas where
  48.           you may want to examine the perl script produced and tweak
  49.           it some.  Here are some of them, in no particular order.
  50.  
  51.           There is an awk idiom of putting int() around a string
  52.           expression to force numeric interpretation, even though the
  53.           argument is always integer anyway.  This is generally
  54.           unneeded in perl, but a2p can't tell if the argument is
  55.           always going to be integer, so it leaves it in.  You may
  56.           wish to remove it.
  57.  
  58.           Perl differentiates numeric comparison from string
  59.           comparison.  Awk has one operator for both that decides at
  60.  
  61.  
  62.  
  63.      Page 1                                           (printed 3/9/94)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      AAAA2222PPPP((((1111))))                UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((LLLLOOOOCCCCAAAALLLL))))                AAAA2222PPPP((((1111))))
  71.  
  72.  
  73.  
  74.           run time which comparison to do.  A2p does not try to do a
  75.           complete job of awk emulation at this point.  Instead it
  76.           guesses which one you want.  It's almost always right, but
  77.           it can be spoofed.  All such guesses are marked with the
  78.           comment "#???".  You should go through and check them.  You
  79.           might want to run at least once with the -w switch to perl,
  80.           which will warn you if you use == where you should have used
  81.           eq.
  82.  
  83.           Perl does not attempt to emulate the behavior of awk in
  84.           which nonexistent array elements spring into existence
  85.           simply by being referenced.  If somehow you are relying on
  86.           this mechanism to create null entries for a subsequent
  87.           for...in, they won't be there in perl.
  88.  
  89.           If a2p makes a split line that assigns to a list of
  90.           variables that looks like (Fld1, Fld2, Fld3...) you may want
  91.           to rerun a2p using the -n option mentioned above.  This will
  92.           let you name the fields throughout the script.  If it splits
  93.           to an array instead, the script is probably referring to the
  94.           number of fields somewhere.
  95.  
  96.           The exit statement in awk doesn't necessarily exit; it goes
  97.           to the END block if there is one.  Awk scripts that do
  98.           contortions within the END block to bypass the block under
  99.           such circumstances can be simplified by removing the
  100.           conditional in the END block and just exiting directly from
  101.           the perl script.
  102.  
  103.           Perl has two kinds of array, numerically-indexed and
  104.           associative.  Awk arrays are usually translated to
  105.           associative arrays, but if you happen to know that the index
  106.           is always going to be numeric you could change the {...} to
  107.           [...].  Iteration over an associative array is done using
  108.           the keys() function, but iteration over a numeric array is
  109.           NOT.  You might need to modify any loop that is iterating
  110.           over the array in question.
  111.  
  112.           Awk starts by assuming OFMT has the value %.6g.  Perl starts
  113.           by assuming its equivalent, $#, to have the value %.20g.
  114.           You'll want to set $# explicitly if you use the default
  115.           value of OFMT.
  116.  
  117.           Near the top of the line loop will be the split operation
  118.           that is implicit in the awk script.  There are times when
  119.           you can move this down past some conditionals that test the
  120.           entire record so that the split is not done as often.
  121.  
  122.           For aesthetic reasons you may wish to change the array base
  123.           $[ from 1 back to perl's default of 0, but remember to
  124.           change all array subscripts AND all substr() and index()
  125.           operations to match.
  126.  
  127.  
  128.  
  129.      Page 2                                           (printed 3/9/94)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      AAAA2222PPPP((((1111))))                UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((LLLLOOOOCCCCAAAALLLL))))                AAAA2222PPPP((((1111))))
  137.  
  138.  
  139.  
  140.           Cute comments that say "# Here is a workaround because awk
  141.           is dumb" are passed through unmodified.
  142.  
  143.           Awk scripts are often embedded in a shell script that pipes
  144.           stuff into and out of awk.  Often the shell script wrapper
  145.           can be incorporated into the perl script, since perl can
  146.           start up pipes into and out of itself, and can do other
  147.           things that awk can't do by itself.
  148.  
  149.           Scripts that refer to the special variables RSTART and
  150.           RLENGTH can often be simplified by referring to the
  151.           variables $`, $& and $', as long as they are within the
  152.           scope of the pattern match that sets them.
  153.  
  154.           The produced perl script may have subroutines defined to
  155.           deal with awk's semantics regarding getline and print.
  156.           Since a2p usually picks correctness over efficiency.  it is
  157.           almost always possible to rewrite such code to be more
  158.           efficient by discarding the semantic sugar.
  159.  
  160.           For efficiency, you may wish to remove the keyword from any
  161.           return statement that is the last statement executed in a
  162.           subroutine.  A2p catches the most common case, but doesn't
  163.           analyze embedded blocks for subtler cases.
  164.  
  165.           ARGV[0] translates to $ARGV0, but ARGV[n] translates to
  166.           $ARGV[$n].  A loop that tries to iterate over ARGV[0] won't
  167.           find it.
  168.  
  169.      EEEENNNNVVVVIIIIRRRROOOONNNNMMMMEEEENNNNTTTT
  170.           A2p uses no environment variables.
  171.  
  172.      AAAAUUUUTTTTHHHHOOOORRRR
  173.           Larry Wall <lwall@jpl-devvax.Jpl.Nasa.Gov>
  174.  
  175.      FFFFIIIILLLLEEEESSSS
  176.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  177.           perl The perl compiler/interpreter
  178.           s2p  sed to perl translator
  179.  
  180.      DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  181.      BBBBUUUUGGGGSSSS
  182.           It would be possible to emulate awk's behavior in selecting
  183.           string versus numeric operations at run time by inspection
  184.           of the operands, but it would be gross and inefficient.
  185.           Besides, a2p almost always guesses right.
  186.  
  187.           Storage for the awk syntax tree is currently static, and can
  188.           run out.
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.      Page 3                                           (printed 3/9/94)
  196.  
  197.  
  198.  
  199.